package www.bplead.com.mydemo.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.List;

import www.bplead.com.controller.action.user.entity.UserInfo;
import www.bplead.com.mydemo.R;

/**
 * Created by wangyangzi on 2016/9/17.
 */
public class RefreshListViewAdapter extends BaseAdapter {

    private Context context;
    private List<UserInfo> userList;

    public RefreshListViewAdapter(Context context,List<UserInfo> userList){
        this.context = context;
        this.userList = userList;
    }

    public void setUserList(List<UserInfo> userList) {
        this.userList = userList;
    }

    public List<UserInfo> getUserList() {
        return userList;
    }

    @Override
    public int getCount() {
        return userList.size();
    }

    @Override
    public Object getItem(int position) {
        return userList.get(position);
    }

    @Override
    public long getItemId(int position) {
        if(userList.get(position).id == null){
            return 0;
        }
        return userList.get(position).id;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        UserInfo userInfo = (UserInfo) getItem(position);

        ViewHolder viewHolder = null;
        if(convertView == null){
            convertView = LayoutInflater.from(context).inflate(R.layout.listview_item,null);
            viewHolder = new ViewHolder();
            viewHolder.nameTV = (TextView) convertView.findViewById(R.id.listview_refresh_item_username);

            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }

        viewHolder.nameTV.setText(userInfo.username);

        return convertView;
    }

    public static class ViewHolder{
        public TextView nameTV;
    }
}
